package org.iabako.client.ui.page.business.client;

import com.google.gwt.user.client.Timer;
import org.iabako.client.config.page.PageConfigEnum;
import org.iabako.client.config.page.PageTagItemEnum;
import org.iabako.client.navigation.NavigationController;
import org.iabako.client.tools.IabakoAsyncCallback;
import org.iabako.client.ui.form.AbstractForm;
import org.iabako.client.ui.form.business.client.ClientForm;
import org.iabako.client.ui.form.business.sale.SaleModifyForm;
import org.iabako.shared.entity.business.AbstractEntity;
import org.iabako.shared.entity.business.Client;

/**
 * TODO javadoc
 * Date: 24/11/13
 * Time: 18:22
 */
public class ClientModify extends ClientForm {

    public ClientModify(AbstractForm abstractForm) {
        super(PageConfigEnum.ClientModify, "", false);

        parentForm = abstractForm;

        String[] params = NavigationController.getInstance().getParams();

        clientServiceAsync.getById(Long.parseLong(params[0]), new IabakoAsyncCallback<AbstractEntity>() {
            public void onSuccess(AbstractEntity result) {
                setClient((Client) result);
                popup.setSelectedTag(PageTagItemEnum.ClientInformation);
                super.onSuccess(result);
            }
        });

        if (parentForm != null) {
            popup.timerAfterClosePopupAnimation = new Timer() {
                public void run() {
                    ((SaleModifyForm) parentForm).setClient(getClient());

                    NavigationController.getInstance().closePopup(simplePopup);
                    NavigationController.getInstance().goTo(parentForm);
                }
            };
        }
    }
}
